package org.egomsl.mw.region;

import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;

public class FileMeta implements Comparable<FileMeta>{
    private int seqNum;
    private boolean reversed;
    private Path path;
    private long size;

    public FileMeta(FileStatus status) {
        this(status, -1, true);
    }

    public FileMeta(FileStatus status, int seqNum) {
        this(status, seqNum, true);
    }

    public FileMeta(FileStatus status, int seqNum, boolean reversed) {
        this.seqNum = seqNum;
        this.reversed = reversed;
        path = status.getPath();
        size = status.getLen();
    }

    public FileMeta(Path path) {
        this(path, -1, true, 0);
    }

    public FileMeta(Path path, int seqNum) {
        this(path, seqNum, true, 0);
    }

    public FileMeta(Path path, int seqNum, boolean reversed) {
        this(path, seqNum, reversed, 0);
    }

    public FileMeta(Path path, int seqNum, boolean reversed, long size) {
        this.path = path;
        this.seqNum = seqNum;
        this.reversed = reversed;
        this.size = size;
    }

    public int getSeqNum() {
        return seqNum;
    }

    public void setSeqNum(int seqNum) {
        this.seqNum = seqNum;
    }

    public Path getPath() {
        return path;
    }

    public void setPath(Path path) {
        this.path = path;
    }

    public String getName() {
        return path.getName();
    }

    public boolean isReversed() {
        return reversed;
    }

    public void setReversed(boolean reversed) {
        this.reversed = reversed;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    @Override
    public int compareTo(FileMeta o) {
        if(seqNum<o.seqNum) return -1;
        else if(seqNum > o.seqNum) return 1;
        else {
            return -o.getPath().getName().compareTo(path.getName());
        }
    }
}
